﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Sinacor.Infra.Tools;

namespace EndPointRegistrationWeb
{
    public partial class Grid : System.Web.UI.Page
    {
        private EndPointDataGrid dataGrid = new EndPointDataGrid("datagridEndPoints", new string[] { "&nbsp;", "Codigo", "Módulo", "Sub-Módulo", "Contrato", "Protocolo" });

        protected void Page_Load(object sender, EventArgs e)
        {
            this.grdForm.Controls.Add(dataGrid);
            this.LoadDataGrid();
        }

        private void LoadDataGrid()
        {
            foreach (EndPoint r in new DataAccess().LoadEndPoints())
            {
                HtmlTableRow row = new HtmlTableRow();
                row.Attributes.Add("onmouseover", "GridOnMouseOver(this)");
                row.Attributes.Add("onmouseout", "GridOnMouseOut(this)");
                row.Attributes.Add("onDblclick", "GridMouseDblClick('datagridEndPoints', this)");
                row.Attributes.Add("onclick", "GridMouseClick('datagridEndPoints', '" + r.CodigoEndPoint.ToString() + "', true)");
                row.Attributes.Add("style", "cursor: hand");
                row.Height = "22";
                row.BgColor = "#ffffff";

                HtmlTableCell cellCheckBox = new HtmlTableCell();
                HtmlTableCell cellCodigo = new HtmlTableCell();
                HtmlTableCell cellModulo = new HtmlTableCell();
                HtmlTableCell cellSubModulo = new HtmlTableCell();
                HtmlTableCell cellContrato = new HtmlTableCell();
                HtmlTableCell cellProtocolo = new HtmlTableCell();

                cellCheckBox.Align = "center";
                cellCodigo.Align = "center";

                cellCheckBox.Controls.Add(new EndPointCheckbox(r.CodigoEndPoint.ToString(), false));
                cellCodigo.InnerHtml = r.CodigoEndPoint.ToString();
                cellModulo.InnerHtml = r.Modulo;
                cellSubModulo.InnerHtml = r.SubModulo;
                cellContrato.InnerHtml = r.Contrato;
                cellProtocolo.InnerHtml = r.Protocolo;

                row.Cells.Add(cellCheckBox);
                row.Cells.Add(cellCodigo);
                row.Cells.Add(cellModulo);
                row.Cells.Add(cellSubModulo);
                row.Cells.Add(cellContrato);
                row.Cells.Add(cellProtocolo);

                dataGrid.Rows.Add(row);
            }
        }
    }
}